{{ extend './layout/main.html'}}


{{block 'content'}}
<link href="/public/stylesheets/login.css" rel="stylesheet" type="text/css"/>
<div id="wrapper">
    <div class="aw-login-box">
        <div class="mod-body clearfix">
            <div class="content pull-left">
                <h1 class="logo"><a href=""></a></h1>
                <h2></h2>
                <form action="/" method="post" id="login_form">
                    <ul>
                        <li>
                            <input type="text" id="aw-login-user-name" class="form-control" placeholder="用户名" name="username" value=""/>
                        </li>
                        <li>
                            <input type="password" id="aw-login-user-password" class="form-control" placeholder="密码" name="password" value=""/>
                        </li>
                        <li class="alert alert-danger hide error_message">
                            <i class="icon icon-delete"></i> <em></em>
                        </li>
                        <li class="last">
                            <input type="submit" class="pull-right btn btn-large btn-primary" value="登录">
<!--                            <label><input type="checkbox" value="1" name="rememberMe" id="rememberMe"/> 记住我 </label>-->
<!--                            <a href="http://wenda.golaravel.com/account/find_password/">&nbsp;&nbsp;忘记密码</a>-->
                        </li>
                    </ul>
                </form>
            </div>
            <!--<div class="side-bar pull-left">
                <img src="../public/images/a.jpg" style="width: 160px">
            </div>-->
        </div>
        <div class="mod-footer">
            <span>还没有账号?</span>&nbsp;&nbsp;
            <a href="/user/register">立即注册</a>
        </div>
    </div>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script type="text/javascript">
    let rememberMe;
    function setCookie() {
        const username = $("#username").val();
        const password = $("#password").val();
        rememberMe = $('#rememberMe').val();
        if (rememberMe === 1) {
            $.cookie("username", username);
            $.cookie("password", password);
        } else {
            $.cookie("password", null);
        }
    }

    // /user/doLogin
    $('#login_form').on('submit', function (e) {
        e.preventDefault();
        if (rememberMe === 1) {
            setCookie();
        }
        const formData = $(this).serialize();
        $.ajax({
            url: '/user/doLogin',
            type: 'post',
            data: formData,
            dataType: 'json',
            success: function (data) {
                if (data.code === '001') {
                    if (confirm('登录成功!去听歌?')) {
                        location.href = '/music/index';
                    }
                } else {
                    alert(data.message);
                }
            }
        })
    });
</script>


{{/block}}